<?

class Admin_Categories extends MY_Controller {

	function Admin_Categories() {

		parent::MY_Controller(TRUE);

	}

	function index() {

		$this->mdl_sessions->set_last_index();

		$this->load->view('admin/categories_index');

	}

	function form() {

		if ($this->session->userdata('last_index') == 'admin_index') {

			$this->mdl_sessions->set_last_index('admin_categories/index');

		}

		if ($this->mdl_categories->validate()) {

			$this->mdl_categories->save();

			redirect($this->session->userdata('last_index'));

		}

		else {

			if (!$_POST and $this->uri_assoc('category_id')) {

				$this->mdl_categories->prep_validation($this->mdl_categories->get(array('category_id'=>$this->uri_assoc('category_id'))));

			}

			$this->load->view('admin/categories_form');

		}

	}

	function delete() {

		$this->mdl_categories->delete();

		redirect($this->session->userdata('last_index'));

	}

	function set_default() {

		$this->mdl_categories->set_default($this->uri_assoc('category_id'));

		$this->load->view('admin/categories_index');

	}

}

?>